package com.lagou.module2.task2;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

public class TestXml {

    public static void main(String[] args) throws DocumentException {

        //1.获取XML解析对象
        SAXReader reader = new SAXReader();

        //2.获取文档对象document
        Document document = reader.read("D:\\PracticeCode\\lagou_java\\Code\\src\\com\\lagou\\module2\\task2\\book.xml");

        //3.获取根元素
        Element rootElement = document.getRootElement();

        //4.获取 根元素下的标签
        List<Element> elements = rootElement.elements();
        for(Element el:elements){

            System.out.println(el.elementText("name") +
                    " " + el.elementText("author") +
                    " " + el.elementText("price") +
                    " " + el.elementText("body")) ;

        }
    }
}
